﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Data;
using System.Xml;

namespace ViennaAdvantageWeb
{
    public partial class _Default : System.Web.UI.Page
    {
        
        StringBuilder sb = new StringBuilder("");
        string tokenKey = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Init();
                string path = Request.QueryString["path"];
                string id = Request.QueryString["id"];
                tokenKey = Request.QueryString["Value"];

                try
                {
                    string name;
                    //string log = MarketSvc.Classes.Utility.GetLog(path, id, out name);
                    string logs = VWebHelper.VHelper.GetLog(path, id, out name);

                    ViewState.Add("Log", logs);

                    SetMessage(logs, name);
                }
                catch (Exception ex)
                {
                    SetMessage(ex.Message, "Error");
                }
            }
        }

        void Init()
        {
            lnkSendMail.Text = "Send Report";
        }

        /// <summary>
        /// Show Message 
        /// </summary>
        /// <param name="strMsg"> string Msg to show</param>
        private void SetMessage(string msg, string name)
        {
            lblName.Text = name;
            lblText.Text = msg;
            lblText.Text = lblText.Text.Replace("\n", "<br />");
        }

        protected void LnkBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect(VWebHelper.VHelper.BaseURL, true);
        }

        protected void btnSendMail_Click(object sender, EventArgs e)
        {
            string resr= VWebHelper.VHelper.SendMail(ViewState["Log"], tokenKey);
            if (resr.Equals("Ok", StringComparison.OrdinalIgnoreCase) || resr.Equals("True", StringComparison.OrdinalIgnoreCase))
            {
                resr = "Mail sent";
            }
            string script = string.Format("alert('{0}');", resr);
           // ViewState.Remove("Log");
            this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "alert", script, true);
        }
    }
}
